package com.neuresys.database.databaseapi;

import com.google.gwt.core.shared.GWT;
import com.neuresys.database.databaseimpl.jssqlite.SQLite;
import com.neuresys.database.implstorage.gwtmobileimpl.WebDatabaseStoreDataService;
import com.neuresys.database.implstorage.indexeddbimpl.IndexedDBStoreDataService;

public class StoreDataServiceFactory {

	private static StoreDataService service=null;
	private  native static boolean isIndexedDBSupported()
	/*-{
		$wnd.indexedDB = $wnd.indexedDB || $wnd.mozIndexedDB
				|| $wnd.webkitIndexedDB || $wnd.msIndexedDB;
	if ($wnd.indexedDB) {
		return true;
	} else
		return false;
}-*/;
	private   static boolean isWebSQLSupported()
	{
		return com.google.code.gwt.database.client.Database.isSupported();
	}
	public static StoreDataService getInstance()
	{
		if (service==null)
		{
			if (isIndexedDBSupported())
			{
				GWT.log("IndexedDB Storage Engine");
				service=new IndexedDBStoreDataService();
			}else
			if (isWebSQLSupported())
			{
				GWT.log("WEBSQL Storage Engine");
				service=new WebDatabaseStoreDataService();
			}
		} 
		return service;
	}
}